package org.genntii.smuserserver.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.genntii.smdomain.entity.ArticleCommentDTO;

import java.util.ArrayList;

@Mapper
public interface ArticleCommentMapper {

    @Select("""
            SELECT\s
                a.*,\s
                c.*
            FROM\s
                Article.Article a
            LEFT JOIN `Comment`.`Comment` c ON a.id = c.article_id
            WHERE a.user_id = #{userId} OR c.user_id = #{userId}
            ORDER BY\s
                GREATEST(a.update_time, c.create_time) DESC -- 使用GREATEST函数来获取两个时间中较晚的一个
            LIMIT #{pageNum},#{pageSize};""")
    ArrayList<ArticleCommentDTO> getArticleComment(@Param("userId") Long userId,
                                                   @Param("pageNum") Integer pageNum,
                                                   @Param("pageSize") Integer pageSize);

}
